home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-28 | 92.4 KB | 2,503 lines | [TEXT/MPS ] |
- #########################################################################
- # Controls.lib
- #========================================================================
- # Description: This is a library of general Virtual User tasks. All of the
- # tasks do their own error checking and status/error reporting.
- # Most of them return a 1 if the action was successful and a 0
- # if the action could not be performed. GetNewFileName() returns
- # a new file name, MatchApp(), the current application's name,
- # and GetXYRandom, a random X,Y coordinate pair. Tasks that do
- # not return a value are marked with an *.
- # The available tasks are listed below in order:
- #
- # Initialization Tasks:
- # InitControlGlobals()
- # PrintGlobalValues()
- #
- # Logging Tasks:
- # LogStr(str, errorCheck,doTargetCheck)
- # TargetInfo(theList)
- # MatchApp(logMe,UpdateAppTitle)
- #
- # Keyboard Tasks:
- # TypeStr(str) *
- # TypeList(List,Key, flag) *
- # KeyEq(Alias,Otherkey) *
- # SpecialKey(Key, keyName, n) *
- #
- # Control Tasks:
- # SelectMenuItem(menuName1, menuName2, menuName3)
- # SelectButton(ButtonName)
- # SelectRadioButton(RadioButtonName)
- # SelectCheckBox(CheckBoxName)
- # CheckYesNo(flag, DocName) *
- #
- # Window Tasks:
- # DialogCheck(FindStaticText, CommitButton)
- # FindWindow(specifier)
- # SelectWindow(specifier)
- # DragWindow(h,v,specifier,absolutely)
- # SizeWindow(X,Y,specifier,absolutely)
- # ZoomWindow(specifier)
- # ScrollWindow(foo,x,y)
- # GetVHScrollBars()
- # CloseWindow(howClose, overwrite, specifier, DocName)
- #
- # Mouse Tasks:
- # MoveRelativeToWindow(x, y, specifier, mouseDown, inset) *
- # MoveMouse(x, y, absolutely , mouseDown) *
- # DrawShapeFrame(specifier, theRect, inset)
- #
- # File Related Tasks:
- # NameOK(NameDoc, replaceFlag)
- # GetNewFileName(name)
- # OpenDoc(namedoc, SelectOpen) *
- #
- # Launch Tasks:
- # Twitcher(appName, numIterations, waitTime)
- # MiniLaunch(appTitle)
- # LaunchTwitch(AppName, Folder, LaunchApp, SetDir)
- #
- # String Tasks:
- # IsSubString(str1, str2)
- # FindPos(char, str, startPos)
- # Substring(_String,_StartChar,_NumChar)
- #
- # Misc. Tasks:
- # Scrapbook(requestElement, ccpFlag, pasteFlag) *
- # PageSetup()
- # GetXYRandom(inset, specifier)
- # IsNumber(whatAmI)
- # PtInRect(thePoint,theRect)
- # CenterOfScreenClick()
- # Quit(OverWrite,DocName,HowQuit)
- #
- # Copyright Apple Computer, Inc. 1985-1991
- # All rights reserved
- #===============================================================================
- # NJV/KTA 5/23/90 Created version 2.03
- # NJV/KTA 7/20/90 Modified to 2.1. - For more info about tasks that
- # have changed since 2.03 the changes please refer to
- # the task header. These changes should not affect your
- # current scripts. The fixes were for added functionality.
- # Globals were added for disabling individual features of
- # LogStr.
- # LogStr()
- # TargetInfo() (New)
- # MatchApp()
- # TypeList() (New)
- # SpecialKey()
- # CheckYesNo()
- # SizeWindow()
- # ScrollWindow()
- # GetVHScrollBars() (New)
- # CloseWindow()
- # MoveRelativeToWindow()
- # MoveMouse()
- # NameOK()
- # OpenDoc()
- # Scrapbook()
- # IsSubString() (New)
- # FindPos() (New)
- # DM 9/18/90 Modified to 2.2. - Added DoSpecTest() and calls to include
- # Cdev.lib.vu and DA.lib.vu
- # DM 9/24/90 Modified CloseWindw, MoveRelativeToWindow and GetXYRandom.
- # All calls are preserved except GetXYRandom. Added
- # general version of DrawShapeFrame.
- # NJV 10/9/90 Bug fix in Scrapbook for 6.0 world
- # NJV 11/27/90 Updated to version 2.4b3 by making the following changes:
- # + Docname wasn't explained in CloseWindow()
- # + Header for Quit() needed to be fixed
- # + Header for FindWindow() needed to be fixed
- # + Header for Opendoc() needed to be fixed
- # + Header for ScrapBook() needed to be fixed
- # + Header for NameOK() needed to be fixed
- # + Full names were taken out of headers
- # + bug fix and header update in SpecialKey()
- # + updated LaunchTwitch() and MiniLaunch() for new
- # version of MiniLauncher 1.3b
- # NJV/KTA 12/18/90 Combined changes from 2 updated versions of Controls.lib
- # KTA 12/20/90 Fixed bug in AppVerify scheme which included changes to
- # LaunchTwitch, LogStr, MatchApp
- # Also updated NameOK to handle dialog change in 7.0
- # KTA 1/2/91 Added global BuildVers.
- # KTA 1/8/91 Changed Scrapbook, Quit
- # NJV/KTA 1/24/91 2.5b4 - Modified LaunchTwitch, Added check for warfare,
- # included Library include of Integrate.lib, added
- # code to support Integrate library
- # NJV 1/28/91 Modified LaunchTwitch to disable integration
- # KTA 2/5/91 Added DialogCheck for checking statictext in Dialogs
- # KTA 2/18/91 InitControlGlobals() - added outputting of Global values.
- # Quit() - while(checkYesNo)
- # ScrapBook() - Global Integration := 0
- # LogStr() - Added LineItemTest
- # LogStr() - Took out Integration if DisableAllLogging
- # NJV 3/28/91 2.5b5 - Updated Headers, changed LaunchTwitch,
- # added PrintGlobals()
- # NJV 3/28/91 2.5b6 - took out integration module and the
- # following tasks not needed by developers:
- # Timer()
- # ETime()
- # DoSpecTestsInitial()
- # DoSpecTestsMiddle()
- # NJV 4/16/91 Added StopOnBug global (implemented in LogStr)
- # NJV 6/25/91 2.5b7 - Added PtInRect routine, modified ZoomWindow
- # for better error checking, modified IsNumber
- # to use VU's new TypeOf function, modified
- # ScrollWindow to do scrollbar enable check
- # correctly.
- #########################################################################
-
-
-
-
- #########################################################################
- #################### GLOBALS #####################
- #########################################################################
- ### Global Library Definitions
- ### If current value is 0 or 1, new value must be a 0 or 1
- ### If current value is true or false, new value must be true or false
- ### If current value is a string, new value must be a string
- ###
- #########################################################################
-
-
- #########################################################################
- # InitControlGlobals()
- #========================================================================
- # Author: NJV
- # Description: Initializes all global variables used by the Controls.lib
- # library. This task should be called immediately after
- # the "Libraries 'Control.lib';" line in the script. It
- # is OK to modify the values of the variables. This is how
- # you customize your VU scripting environment and the way
- # that your scripts will react using this library.
- # Parameters: None
- # Returns: Nothing
- # Examples: InitControlGlobals();
- # Assumptions: None
- #
- ################################################################################
- ########### OK to modify the following GLOBAL Settings - Be ###########
- ########### careful that you understand what the Global is used for ###########
- ################################################################################
- #========================================================================
- # History:
- # NJV 3/28/91 Created
- #########################################################################
- Task InitControlGlobals() begin
- println "Initializing Globals in Controls.lib 2.5b7";
-
- ## If AppVerify is set to 1, then the Application Verification scheme will
- ## be activated. This scheme is documented in the "SIAC's Reference"
- ## document (which accompanies this library on the Developer CD).
- ##
-
- global AppVerify := 0; # 1 to enable Application Verification Scheme
- # 0 to disable Application Verification Scheme
-
- global StopOnBug := 0; # 1 to stop when LogStr encounters a warning (error)
- # message
-
- ### To set Target descriptor output ###
- global TargetInfoDescriptor := 'Target'; # Descriptor to use 'Target' is the one only defined currently
- global TargetCheck := 0; # 1 for target title; 2 for target application title
-
- global BugsOn := 0; # set to 1 for known bugs to be tested
-
- ############################################################################
- ####### DO NOT modify any of the following GLOBAL Settings - ############
- ####### DisableAllLogging may be reset during script execution ############
- ############################################################################
- Sys := match[system v:?Sysname]; # To match system build
- global BuildVers := "{Sysname}";
- if ((Sysname ~= /≈7.0≈/) or (Sysname ~= /≈Warfare≈/) or (Sysname ~= /≈Regatta≈/))
- Global isSys7 := true;
- else
- Global isSys7 := False;
-
- global LogStrCount := 0; # Initializes our LogStr Counter
- global LastSavedFile; # Contains the name of the last file saved in NameOK();
- global AppTitle := ""; # Current application title for AppVerify()
- global PrevAppTitle := ""; # Previous application title for twitching
- global DisableAllLogging := 0; # 1 if no logging (run time modify only)
- Global FileShareFlag; # Holds the current status of Filesharing if
- PrintGlobals(); # print the global values to output
- println;
- end; # SharingSetup() was called.
-
-
- #########################################################################
- # PrintGlobals()
- #========================================================================
- # Author: NJV
- # Description: Prints the values of all Control Globals
- # Parameters: None
- # Returns: Nothing
- # Examples: PrintGlobals();
- # Assumptions: None
- #========================================================================
- # History:
- # NJV 3/28/91 Created
- #########################################################################
- task PrintGlobals() begin
- global BuildVers;
-
- if (global DisableAllLogging)
- println "All logging is disabled";
- else
- println "All logging is enabled";
-
- if (global AppVerify)
- println "The 'Application Verification' scheme is turned - ON";
- else
- println "The 'Application Verification' scheme is turned - OFF";
-
- if (global TargetCheck) begin
- if (TargetCheck= 1)
- TCItem := "the target's 'Title'";
- else if (TargetCheck= 2)
- TCItem := "the title of the target's current 'Application'";
- println "The global 'TargetCheck' is set to output - {TCItem}";
- end;
-
- if (global BugsOn)
- println "The global 'BugsOn' has been activated - Cross your fingers!!!";
-
- if (global Spectest) # DoSpecTestsInitial and DoSpecTestsMiddle
- println "The global 'Spectest' is - ON. Does this effect you???";
-
- Println "The current system is - '{BuildVers}'";
- end;
-
- #########################################################################
- # LogStr(str, errorCheck,doTargetCheck)
- #========================================================================
- # Author: KTA
- # Description: Match the target and print it with whatever is passed
- # to it in the 'str' parameter. If the errorCheck
- # parameter is 1, then the current application will be
- # checked to make sure it is the same as the expected
- # application. If it is not, LogStr will assume that the
- # application has crashed and will abort the script.
- # If the errorCheck parameter is not passed, then the
- # default behavior will not perform this check.
- # Parameters: str - string to be printed
- # errorCheck - 0 to bypass error checking
- # 1 to enable error checking
- # targetCheck - 0 to bypass calling of TargetInfo
- # - theList, which is
- # theList[1] - what to match for - default 'Target'
- # theList[2] - Specifier of what info to return
- # If theList[1] = 'Target'then
- # if theList[2] =
- # 1 - Return Title for target
- # 2 - Returns Application running on Target
- # Returns: Nothing
- # Examples: LogStr("It worked");
- # LogStr("It worked",1,1);
- # LogStr("It worked",1,{1,2});
- # Assumptions: None
- #========================================================================
- # History:
- # KTA 4/1/90 Created
- # KTA 4/29/90 This routine now checks to make sure the global
- # AppTitle equals the current application running -
- # if not, it assumes that the target crashed and
- # aborts the script.
- # NJV 5/15/90 Added errorCheck parameter for disabling error
- # checking.
- # NJV 7/9/90 Added targetCheck for disabling target matching
- # NJV/KTA 7/13/90 Added TargetInfo mechanism
- # KTA 7/19/90 Added key equivelant 'Q'; to quit the current app if
- # it doesn't match
- # NJV 7/24/90 Moved LogStrCount into not DisableAllLogging block
- # KTA 8/2/90 Added - if not( theAppTitle ~= /≈{global AppTitle}≈/)
- # NJV/KTA 12/18/90 Added - Retry for AppVerify
- # KTA 12/20/90 Reworked errorCheck to work with new MatchApp
- # KTA 2/18/91 Added LineItemTest
- # KTA 2/19/91 Took out integration if DisableAllLogging is on.
- # NJV 3/31/91 Took out integration for Developer CD - not needed
- # NJV 3/31/91 Took out LineItemTest
- # NJV 4/16/91 Added StopOnBug block to stop on warning message
- #########################################################################
- task LogStr(str, errorCheck := global AppVerify,doTargetCheck := global TargetCheck) begin
- global AppTitle;
- theStr := '';
-
- if (global StopOnBug) begin
- if (isSubString("!@#$%",str)) # it's a warning message, exit script
- exit;
- end;
-
- if (doTargetCheck)
- theStr := TargetInfo(doTargetCheck);
- if (not global DisableAllLogging) begin
- global LogStrCount := LogStrCount + 1;
- println LogStrCount," - ",str," {theStr}";
- end;
- if (errorCheck) begin
- theAppTitle := MatchApp(0,0);
- retry := 2;
- while not(theAppTitle ~= /≈"{AppTitle}"≈/) begin # assume target crashed if app name not match
- theAppTitle := MatchApp(0,0);
- if retry begin
- retry := retry - 1;
- LaunchTwitch(AppTitle,, 0);
- end;
- else begin
- println "*** Current application: '{theAppTitle}' *** Expected application: '{AppTitle}'";
- println "*** Target application is off track - aborting script and typing key Equivalent 'Q'";
- PressKey K:{CommandKey};
- Type k: {'q'};
- ReleaseKey K:{CommandKey};
- exit;
- end;
- end;
- end;
- Return(1);
- end; # LogStr()
-
-
- #########################################################################
- # TargetInfo(theList)
- #========================================================================
- # Author: NJV/KTA
- # Description: Match whatever is specified in global TargetInfoDescriptor
- # and will return the appropriate string.
- # Parameters: theList[1] - what to match for - default 'Target'
- # theList[2] - Specifier of what info to return
- # If theList[1] = 'Target'then
- # if theList[2] =
- # 1 - Return Title for target
- # 2 - Returns Application running on Target
- # Returns: Str
- # Examples: global TargetInfoDescriptor := 1;
- # global TargetInfoDescriptor :={1,2};
- #========================================================================
- # History:
- # NJV/KTA 7/13/90 Created
- #########################################################################
- task TargetInfo(theList) begin
- theDesc := global TargetInfoDescriptor;
- if (not isList) begin # a single number
- list2 := {theList};
- end;
- else begin # a list
- list2 := theList;
- if (not card(list2)) # a single number
- list2 := {theList};
- end;
-
- # load theDescInfo with the info on the specified target
- if (theDesc = 'Target') begin
- theDescInfo := match [target]!;
- TargetTitle := theDescInfo.t;
- App := theDescInfo.a;
- theAppTitle :=App[1].t;
-
- if not theDescInfo
- return('');
- str := "(Target -";
- end;
-
- for each item in list2 begin
- if ((theDesc = 'Target') and (item = 1)) # title
- str := "{str} Title:∂'{TargetTitle}∂'";
- else if ((theDesc = 'Target') and (item = 2)) # App
- str := "{str} Application:∂'{theAppTitle}∂'";
- # else if ((theDesc = 'Target') and (item = 3)) begin # CPU
- # theCPU := theDescInfo.n;
- # str := "{str} CPU: " + {theCPU};
- # end;
- end;
-
- str := "{str})";
- return(str);
- end;
-
-
- #########################################################################
- # MatchApp(logMe,UpdateAppTitle)
- #========================================================================
- # Author: KTA
- # Description: This routine will match the current Application and,
- # if the logMe parameter is 1, will log the current
- # application name by passing it to LogStr(). If a
- # parameter is not passed, the default behavior will
- # log the application's title. This routine will also
- # set the global AppTitle to the application's title.
- # Output appears in the following format:
- # [application t:"Finder"]
- # Parameters: logMe - 1 to print the current application's title
- # 0 not to print the application's title
- # UpdateAppTitle - 1 to update the global AppTitle
- # - 0 not to update global AppTitle
- # Return Value: string holding current application's title
- # Examples: MatchApp();
- # Assumptions: there is an active application
- #========================================================================
- # History:
- # KTA 3/16/90 Created
- # KTA 4/28/90 Makes a call to global Apptitle to Verify App
- # KTA 5/7/90 Added parameter to allow bypassing of LogStr() call.
- # NJV 5/13/90 Now returns title of application
- # KTA 7/13/90 Took out initial 5 second wait
- # KTA 12/20/90 Added UpdateAppTitle
- #########################################################################
- task MatchApp(logMe := 1, UpdateAppTitle :=1) begin
- AppName := match[application];
- if UpdateAppTitle
- global AppTitle := AppName.t; #to Verify App
- else begin
- TheAppTitle := AppName.t;
- Return(TheAppTitle);
- end;
- str := "The current application is '{AppTitle}'";
- temp := global DisableAllLogging;
- if logMe begin
- DisableAllLogging := 0;
- LogStr(str);
- end;
- DisableAllLogging := temp;
- return(AppTitle);
- end; # MatchApp()
-
- #########################################################################
- # TypeStr(str)
- #========================================================================
- # Author: KTA
- # Description: This routine will type whatever is passed in as the String.
- # Parameters: str - string to be typed
- # Returns: Nothing
- #========================================================================
- # History:
- # KTA 1/20/90 Created
- # KTA 1/9/91 Added default parameter ''
- #########################################################################
- task TypeStr(str :='') begin
- type k:{str};
- LogStr("Typed '{str}'");
- end; # TypeStr()
-
-
- #########################################################################
- # TypeList(theList,Key, flag)
- #========================================================================
- # Author: KTA
- # Description: This routine will type each item in the {list} and the
- # selected special key after each item. If flag = 0 the
- # special key will be suppressed after the last item.
- # Parameters: theList - list holding strings to type
- # Key - int representing key to type after the item
- # has been typed.
- # key := 1 (ReturnKey)
- # Key := 2 (TabKey)
- # Key := 3 (EnterKey)
- # flag - 1 to type special key after last item in list
- # 0 to disable typing of last special key
- # Return Value: None
- # Examples: TypeList({'A','list', 'of items'},2); To type each item
- # and then the tabKey
- # Assumptions: None
- #========================================================================
- # History:
- # KTA 7/1/90 Created
- # DMM 7/2 Flag to type special key after last item
- # KTA 8/20/90 Added check to see if key is defined before adding 'and' to {item}
- ################################################################################
- task TypeList(theList,Key := 0, flag := 0) begin
- x := 0;
- y := card(theList);
- if (flag) #Type final Special Key after the last item
- y := y +1;
- for each item in theList begin
- x := x + 1;
- KeyName := '';
- type k:{item};
- if (x < y) begin #don't suppress special key after last item
- if ((key = 1) or (key = 'ReturnKey')) begin
- type k:{ReturnKey};
- keyName := 'the Return Key';
- end;
- else if ((key = 2) or (key = 'TabKey')) begin
- type k:{TabKey};
- keyName := 'the Tab Key';
- end;
- else if ((key = 3) or (key = 'EnterKey')) begin
- type k:{EnterKey};
- keyName := 'the Enter Key';
- end;
- end;
- if ((x < y) and (Key <> 0) and ((item <> "") or (IsNumber(item))))
- item := "∂'{item}∂' and ";
- LogStr("Typed {item}{KeyName}");
- end;
- end; # TypeList
-
-
- #########################################################################
- # KeyEq(Alias,Otherkey)
- #========================================================================
- # Author: KTA
- # Description: This routine will select the Keyboard Equiv <alias>
- # Parameters: alias - string holding character to be typed with
- # command key down.
- # OtherKey - int representing special keys to hold down in
- # conjunction with the command key
- # 0 - no other keys are to be held down
- # 1 - Shift key
- # 2 - Option key
- # Returns: None
- # Examples: KeyEq("q");
- #========================================================================
- # History:
- # KTA 4/1/90 Created
- # KTA 7/31/90 Added MatchApp for 'w' and 'q'
- # KTA/PF 8/14/90 Added Shift key Functionality
- # KTA 8/16/90 Added Option key Functionality
- #########################################################################
- task KeyEq(Alias,Otherkey := 0) begin
- if (Otherkey =1) begin
- pressKey k:{ commandKey,ShiftKey };
- type k : { alias };
- releaseKey k:{ commandKey,ShiftKey };
- LogStr("Pressed the ∂('{alias}'∂) key and the Command-Shift keys");
- end;
- else if (Otherkey = 2) begin
- pressKey k:{ commandKey,Optionkey };
- type k : { alias };
- releaseKey k:{ commandKey,Optionkey };
- LogStr("Pressed the ∂('{alias}'∂) key and the Command-Option keys");
- end;
- else begin
- pressKey k:{ commandKey };
- type k : { alias };
- releaseKey k:{ commandKey };
- if (global AppVerify) begin
- if ((alias = 'w') or (alias = 'q')) begin
- wait(2);
- matchApp(0);
- end;
- end;
- LogStr("Pressed the ∂('{alias}'∂) key and the Command key");
- end;
- end; # KeyEq()
-
-
- #########################################################################
- # SpecialKey(Key,keyName,n)
- #========================================================================
- # Author: KTA
- # Description: This routine will type whatever SpecialKey is entered
- # However it will only log the name of the special character
- # if the special key name is also passed in as a String in
- # the keyName parameter.
- # Parameters: Key - the VU key-word for the special key to be typed
- # keyName - the string name of the special key
- # n - number of times to type the special key (default = 1)
- # Returns: Nothing
- # Examples: SpecialKey(TabKey,"TabKey");
- #========================================================================
- # History:
- # KTA 4/25/90 Created
- # KTA 7/5/90 Added n parameter for number of times to be completed.
- # NJV 11/27/90 bug fix - if no keyName and n > 1, then str was typed
- # every time instead of once. Also updated header.
- #########################################################################
- task SpecialKey(Key,keyName:="",n :=1) begin
- for x := 1 to n do
- type k:{ Key };
- if (n <> 1) begin
- if (keyName ="")
- LogStr("Typed some special key - ({n}) times");
- else
- LogStr ("Typed {keyName} - ({n}) times");
- end;
- else begin
- if (keyName ="")
- LogStr("Typed some special key");
- else
- LogStr ("Typed {keyName}");
- end;
- end; # SpecialKey()
-
-
- ########################################################################
- # SelectMenuItem(menuName1, menuName2, menuName3)
- #=======================================================================
- # Author: SL
- # Description: Selects the menu item by its name.
- # Parameters: menuName1 := Menu item to be selected.
- # menuName2 := Menu name if non-hier menu and
- # Level 2 menu item if hier menu.
- # menuName3 := "" if non-hier menu.
- # Menu name if hier menu.
- # Returns: menuTitle - MenuItem name that selection was successful
- # 0 - Couldn't select menu item
- # Notes: Do not have to pass 'menuName2' or 'menuName3'
- # as a parameter. In that case, default value, "",
- # will be used.
- #=======================================================================
- # History:
- # SL 4/4/90 Created
- # KTA 5/16/90 MatchApp Verification
- # KTA 8/7/90 Return menuTitle
- ########################################################################
- task SelectMenuItem(menuName1, menuName2 := "", menuName3 := "")
- begin
- if (menuName3 = "") # Match non-hier menus
- begin
- ourMenuItem := match [menuItem t: menuName1 m:[menu t: menuName2]];
- if (ourMenuItem = [])
- ourMenuItem := match [menuItem t: menuName1];
- end;
- else
- begin # Match hier menus
- ourMenuItem :=match [menuItem t:menuName1
- m:[menuitem t:menuName2
- m:[menu t:menuName3]]];
- if (ourMenuItem = [])
- ourMenuItem :=match [menuItem t:menuName1 m:[menuItem t:menuName2]];
- if (ourMenuItem = [])
- ourMenuItem :=match [menuItem t:menuName1];
- end; # else
-
- if (ourMenuItem = [])
- begin
- LogStr("!@#$% Could not find menu item {menuName1} to select");
- return(0);
- end;
- else
- if (ourMenuItem.e = false) begin
- LogStr("!@#$% Menu item {menuName1} is not enabled to select.");
- return(0);
- end;
- else
- select ourMenuItem!;
- menuTitle := ourMenuItem.t;
- if (global AppVerify) begin
- if ((menuTitle = 'Close') or (menuTitle = 'Quit')) begin
- wait(2);
- matchApp(0);
- end;
- end;
- LogStr("Selected the '{menuTitle}' menu item");
- return(menuTitle);
- end; # SelectMenuItem()
-
-
- #########################################################################
- # SelectButton(ButtonName)
- #========================================================================
- # Author: KTA
- # Description: This routine will select the button named (ButtonName)
- # Parameters: ButtonName - string holding name of button to select
- # Returns: 0 - Couldn't select button
- # 1 - Selected button OK
- #========================================================================
- # History:
- # KTA 3/20/90 Created
- # NJV 5/13/90 Added checking to assure button is enabled
- #########################################################################
- task SelectButton(ButtonName) begin
- rix := match [button t:ButtonName e:1]!;
- if rix begin
- Select [button t:ButtonName];
- str := "Selected Button titled '{ButtonName}'";
- LogStr(str);
- return(1);
- end;
- else begin
- if (match [button t:ButtonName]!)
- str := "!@#$% Couldn't select button named '{ButtonName}' because it's not enabled";
- else
- str:= "!@#$% There was no button named '{ButtonName}'";
- LogStr(str);
- return(0);
- end;
- end; # SelectButton()
-
- #########################################################################
- # SelectRadioButton(RadioButtonName)
- #========================================================================
- # Author: KTA
- # Description: This routine will select RadioButton named (RadioButtonName)
- # Parameters: RadioButtonName - string name of radio button to select
- # Returns: 0 - Couldn't select radio button
- # 1 - Selected button OK
- #========================================================================
- # History:
- # KTA 3/20/90 Created
- # NJV 5/13/90 Added checking to assure radio button is enabled
- #########################################################################
- task SelectRadioButton(RadioButtonName) begin
- rix := match [RadioButton t:RadioButtonName e:1]!;
- if rix begin
- Select [RadioButton t:RadioButtonName];
- str := "Selected radio button titled '{RadioButtonName}'";
- LogStr(str);
- return(1);
- end;
- else begin
- if (match [RadioButton t:RadioButtonName]!)
- str := "!@#$% Couldn't select radio button named '{RadioButtonName}' because it's not enabled";
- else
- str:= "!@#$% There was no radio button named '{RadioButtonName}'";
- LogStr(str);
- return(0);
- end;
- end; # SelectRadioButton()
-
- #########################################################################
- # SelectCheckBox(CheckBoxName)
- #========================================================================
- # Author: KTA
- # Description: This routine will select CheckBox named (CheckBoxName)
- # Paramters: CheckBoxName - string name of check box to select
- # Returns: 0 - Couldn't select check box
- # 1 - Selected check box OK
- #========================================================================
- # History:
- # KTA 3/20/90 Created
- # NJV 5/13/90 Added checking to assure check box is enabled
- #########################################################################
- task SelectCheckBox(CheckBoxName) begin
- rix := match [CheckBox t:CheckBoxName]!;
- if rix begin
- Select [CheckBox t:CheckBoxName];
- str := "Selected check box titled '{CheckBoxName}'";
- LogStr(str);
- return(1);
- end;
- else begin
- if (match [CheckBox t:CheckBoxName]!)
- str := "!@#$% Couldn't select check box named '{CheckBoxName}' because it's not enabled";
- else
- str:= "!@#$% There was no check box named '{CheckBoxName}'";
- LogStr(str);
- return(0);
- end;
- end; # SelectCheckBox()
-
-
- #########################################################################
- # CheckYesNo(flag, DocName)
- #========================================================================
- # Author: SL
- # Description: Checks for dialog boxes with "Yes" (or "OK") and "No"
- # buttons. If they are found, clicks one of the buttons
- # depending on the 'flag' parameter.
- # Parameters: flag - TRUE - Selects "Yes" or "OK" button.
- # FALSE - Selects "No" button.
- # DocName - Name that docment will be saved with.
- # Returns: Nothing
- #========================================================================
- # History:
- # SL 4/3/90 Created
- # KTA/NV 7/17/90 Added DocName parameter for Nameok
- #########################################################################
- task CheckYesNo(flag := true, DocName := "")
- begin
- wait(1);
- yesBtn := match[button t:"Yes" w:[window o:1]]!;
- noBtn := match[button t:"No" w:[window o:1]]!;
- okBtn := match[button t:"Ok" w:[window o:1]]!;
- if (yesBtn or okbtn ) and flag begin
- if (yesBtn)
- SelectButton("Yes");
- else if (okbtn)
- SelectButton("OK");
- wait(1);
- if (match[button t:"Save"]!) or (match[button t:"OK"]!) # If SF dialog comes up #
- NameOk(DocName,true);
- else
- type k:{ReturnKey};
- end; # if
- else
- if noBtn and (not flag)
- SelectButton("No");
- wait(1);
- end; # CheckYesNo()
-
-
- #########################################################################
- # FindWindow(specifier)
- #========================================================================
- # Author: DM
- # Description: FindWindow will return the descriptor of the window
- # specified by the parameter specifier.
- # Parameters: specifier - if string, then it holds title of window
- # if integer, then it holds ordinality of window
- # Returns: 0 - Couldn't find the window
- # 1 - found the window OK
- #========================================================================
- # History:
- # DM 9/27/90 Created
- # NJV 11/27/90 Added documentation
- #########################################################################
- task FindWindow(specifier := "None") begin
- if(specifier = "None") begin
- LogStr("Null specifier passed as a parameter to FindWindow");
- return 0;
- end;
- if (not (IsNumber(specifier))) begin
- theDesc := match [window t:specifier]!;
- if (not theDesc) begin
- LogStr("!@#$% Couldn't match a window of title {specifier}");
- return(0);
- end;
- end;
- else if(specifier > 0) begin
- theDesc := match[window o:specifier]!;
- if (not theDesc) begin
- LogStr("!@#$% Couldn't match a window of ordinality {specifier} with a grow box");
- return(0);
- end;
- end;
- else if(specifier = 0) begin
- theDesc := match[window c:true g:true]!;
- if (not theDesc) begin
- LogStr("!@#$% Couldn't match a window with a close and grow box");
- return(0);
- end;
- end;
- else if (specifier < 0) begin
- scrList := collect[screen]!;
- theDesc := scrList[-specifier];
- end;
- return theDesc;
- end;
-
- ########################################################################
- # DialogCheck(FindStaticText,CommitButton)
- #=======================================================================
- # Author: KTA
- # Description: This routine will to match a dialog of ordinality 1,
- # with StaticText - {FindStaticText}, if found it will select the
- # Button - {CommitButton}.
- # Parameters: FindStaticText - StaticText string that you want to match
- # CommitButton - Button to select if the static text is found.
- # Returns: 1 - Found FindStaticText and selected CommitButton
- # 0 - Couldn't find FindStaticText
- #=======================================================================
- # History:
- # KTA 2/5/91 Created
- # KTA 2/19/91
- ########################################################################
- task DialogCheck(FindStaticText :='', CommitButton :="OK")
- begin
- DialogWin := collect[staticText w:[window o:1 c:false s:dialog]]!;
- if (DialogWin)
- begin
- for each StaticItem in DialogWin
- begin
- theStaticText := StaticItem.t;
- if not( theStaticText = '')
- begin
- if(IsSubString(FindStaticText, theStaticText))
- begin
- println;
- LogStr("Found Dialog: '{theStaticText}'");
- SelectButton(CommitButton);
- println;
- return(theStaticText);
- end;
- end;
- end;
- end;
- else
- return(0);
- end; #DialogCheck()
-
- ########################################################################
- # SelectWindow(specifier)
- #=======================================================================
- # Author: NJV
- # Description: This routine will select a window specified by
- # ordinality or title.
- # Parameters: specifier - holds the title or ordinality of window to
- # select.
- # Returns: 1 - Selected window OK
- # 0 - Couldn't find window to select
- #=======================================================================
- # History:
- # NJV 4/7/90 Created
- # NJV 5/13/90 Condensed two parameters to one
- # DM 9/27/90 Optimized and added FindWindow
- # ECH 11/7/90 Changed default parameter to 0 to let FindWindow
- # do its work.
- ########################################################################
- task SelectWindow(specifier := 0) begin
- theWind := FindWindow(specifier);
- if theWind begin
- windOrd := theWind.o;
- title := theWind.t;
- select [window o:windOrd t:title]!;
- LogStr("Selected window of ordinality {windOrd} (titled '{title}')");
- return(1);
- end;
- else begin
- if(IsNumber(specifier))
- Str1 := "!@#$% There was no window of ordinality {specifier} to select";
- else
- Str1 := "!@#$% There was no window titled '{specifier}'";
- LogStr(Str1);
- return(0);
- end;
- end; # SelectWindow()
-
-
- #########################################################################
- # DragWindow(h,v,specifier,absolutely)
- #========================================================================
- # Author: KTA
- # Description: This routine will drag the specified window
- # 'h' pixels horizontally (-h drags left) and 'v' pixels
- # vertically (-v drags up)
- # Parameters: h - Horizontal pixel offset to drag the window
- # v - Vertical pixel offset to drag the window
- # specifier - holds title or ordinality of window to drag
- # absolutely - 1 if absolute drag
- # 0 if relative drag
- # Returns: 1 - Dragged window OK
- # 0 - Couldn't find window to drag
- #========================================================================
- # History:
- # KA 4/6/90 Created
- # NJV 4/7/90 Allows for dragging by title or ordinality
- # NJV 4/26/90 Changed to allow for absolutely or relative drag
- # NJV 5/13/90 Condensed parameter list
- # DM 9/27/90 Optimized and added FindWindow
- # Changed specifier default to 0 so it will match the
- # first document window.
- #########################################################################
- task DragWindow(h := "random", v := "random", specifier:=0,absolutely:=1) begin
- if (h = "random") begin # user wants random coordinates
- xyRandom := getXYRandom(,-1);
- h := xyRandom[1];
- v := xyRandom[2];
- end;
-
- theWind := FindWindow(specifier);
- if theWind begin
- windOrd := theWind.o;
- title := theWind.t;
- if (specifier > 0)
- Str1 := "of ordinality {specifier} ";
- else if (specifier = 0)
- Str1 := "with grow and zoom box ";
- else if( not IsNumber(specifier))
- Str1 := "";
- if (absolutely) begin
- drag [window o:windOrd t:title]! a:{h,v}; #To drag the window
- str := "Dragged window {Str1}titled '{title}' to absolute location {h},{v}";
- end;
- else begin
- drag [window o:windOrd t:title]! r:{h,v}; #To drag the window
- str := "Dragged window {Str1}titled '{title}' {h} pixels horizontally and {v} pixels vertically";
- end;
- LogStr(str);
- return(1);
- end;
- # Error messages
- else begin
- if (specifier > 0)
- Str1 := "!@#$% There was no window of ordinality {specifier} to drag";
- else if (specifier = 0)
- Str1 := "!@#$% Couldn't find window with grow and zoom box to drag";
- else if( not IsNumber(specifier))
- Str1 := "!@#$% There was no window titled '{specifier}' to drag";
- end;
-
- LogStr(Str1);
- return(0);
- end; # DragWindow()
-
-
- #########################################################################
- # SizeWindow(X,Y,specifier,absolutely)
- #========================================================================
- # Author: KTA
- # Description: This routine will match and resize the specified window.
- # If only the X and Y parameters are passed, the default
- # behavior will size the first window containing a grow
- # and zoom box absolutely. If no parameters are passed,
- # then the default behavior will generate random
- # coordinates on the main screen and resize the window
- # to an absolute size. If the user passes in the string
- # "random" for x and y and passes 0 for the absolutely
- # parameter (for a resize relative to current size),
- # then checks are performed to assure that new size will
- # not go off of the screen. If it does, the values will
- # be adjusted so that the largest the window can be sized
- # is to the border of the screen.
- # Parameters: X,Y - the Width and Height to resize the window
- # specifier - title or ordinality of window to be sized
- # absolutely - 1 if resize window absolute
- # 0 if resize window relative
- # Returns: 1 - Resized window OK
- # 0 - Couldn't resize window
- # Examples: SizeWindow(200,400);
- # Note: #### The Zoom and the Grow trait are matched!!!
- # Some Apps don't work if just the g: trait is used.
- #========================================================================
- # History:
- # NJV 11/20/89 Created
- # KTA 1/20/90 Implemented LogStr()
- # NJV 4/26/90 Added byOrdinality, value, and absolutely parameters
- # NJV 5/14/90 Condensed byOrdinality and value into specifier parameter
- # NJV 5/15/90 Added random function
- # NJV/KTA 7/13/90 Bug fix - only checks window for zoom box under default
- # NJV 7/19/90 Cut routine size in half.
- # DM 9/27/90 Optimized and added FindWindow
- # Changed specifier default to 0 so it will match the
- # first document window.
- #########################################################################
- task SizeWindow(x:="random", y:="random", specifier := 0, absolutely := 1) begin
- randomFlag := 0;
- if (x = "random") begin # user wants to size window randomly
- xyRandom := getXYRandom(,-1);
- x := xyRandom[1];
- y := xyRandom[2];
- randomFlag := 1;
- if (not absolutely) begin # relative - include possible negative values
- negative := random(0,1);
- if (negative = 1) begin
- x := 0 - x;
- y:= 0 - y;
- end;
- end;
- end;
-
- theWind := FindWindow(specifier);
- specifier := theWind.o;
- title := theWind.t;
-
- # specifier = ordinality of window to size
- # title = title of window to size
- if randomFlag begin # make sure if random numbers were generated that new window size is on screen
- theWindRect := theWind.r;
- match [screen r:?theScrnRect]!;
- if (absolutely) begin # get Top-Left corner coord of window
- if ((theWindRect[1] + x) > theScrnRect[3]) # x value off of screen - adjust it
- x := theScrnRect[3] - theWindRect[1];
- if ((theWindRect[2] + y) > theScrnRect[4]) # y value off of screen - adjust it
- y := theScrnRect[4] - theWindRect[2];
- end;
- else begin # size window relative - get Bottom-Right coord of window
- if (not negative) begin
- if ((theWindRect[3] + x) > theScrnRect[3]) # x value off of screen
- x := theScrnRect[3] - theWindRect[3];
- if ((theWindRect[4] + y) > theScrnRect[4]) # y value off of screen
- y := theScrnRect[4] - theWindRect[4];
- end;
- ### the 20 in the equations below must be there. This is to assure that
- ### the window is not sized below 20 horizontally (the size box is 20 pixels,
- ### and attempts to size smaller than that will cause VU to display an
- ### "Out of bounds" error.
- else begin # negative value - must check against upper-left corner of screen
- if ((theWindRect[3] + x - 20) < theScrnRect[1]) # x value off of screen
- x := 20 - theWindRect[3] - theScrnRect[1];
- if ((theWindRect[4] + y - 20) < theScrnRect[2]) # y value off of screen
- y := 20 - theWindRect[4] - theScrnRect[2];
- end;
- end;
- end;
- if (absolutely) begin
- size [window t:title o:specifier g:true ] W:x H:y; #To size the window
- match [window t:title o:specifier g:true r:?theWindRect]!;
- x := theWindRect[3] - theWindRect[1];
- y := theWindRect[4] - theWindRect[2];
- str := "Resized window '{title}' absolute {x} pixels wide and {y} pixels high";
- end;
- else begin
- if (randomFlag) begin # include negative offsets for random size
- match [window t:title o:specifier g:true r:?theOrigWindRect]!;
-
- size [window t:title o:specifier g:true ] r:{ x, y }; #To size the window
-
- match [window t:title o:specifier g:true r:?theWindRect]!;
- x := theWindRect[3] - theOrigWindRect[3];
- y := theWindRect[4] - theOrigWindRect[4];
- end;
- else begin
- size [window t:title o:specifier g:true] r:{ x, y }; #To size the window
- match [window t:title o:specifier g:true r:?theWindRect]!;
- x := theWindRect[3] - x;
- y := theWindRect[4] - y;
- end;
- str := "Resized window '{title}' relative {x} pixels wide and {y} pixels high";
- end;
- LogStr(str);
- return(1);
- end; # SizeWindow()
- ### Set - No variable definition exists for oldType.
- ### Set - No variable definition exists for oldBack.
- ### Set - No variable definition exists for oldCase.
-
-
- #########################################################################
- # ZoomWindow(specifier)
- #========================================================================
- # Author: KTA
- # Description: Selects the zoom box on the requested window. If no
- # parameters are passed, then the default behavior will
- # zoom the first window with a zoom box.
- # Parameters: specifier - holds title or ordinality of window to zoom
- # Returns: 0 - Couldn't zoom the window
- # 1 - Zoomed the window OK
- #========================================================================
- # History:
- # KTA 3/8/90 Created
- # NJV 4/7/90 Changed name to ZoomWindow and added title parameter
- # to zoom a window by title instead of ordinality 1
- # NJV 4/9/90 Changed title parameter to byOrdinality and specifier
- # to allow window specification by title or ordinality.
- # NJV 5/13/90 Condensed parameters to a single parameter
- # Took out select window call
- # DM 9/27/90 Optimized and added FindWindow
- # Changed specifier default to 0 so it will match the
- # first document window.
- # NJV 6/25/91 Added check to assure zoom box is on screen
- #########################################################################
- task ZoomWindow(specifier:= 0) begin
- theWind := FindWindow(specifier);
- if theWind begin
- windOrd := theWind.o;
- title := theWind.t;
- zoomBox := theWind.z;
- theRect := theWind.r; # njv - added 6/25/91
- theHitPoint := {theRect[3]-20,theRect[2]}; # hit point for zoom box
- hitPointOffScreen := false;
-
- if (specifier > 0)
- Str1 := "of ordinality {specifier} ";
- else if (specifier = 0)
- Str1 := "with a zoom box ";
- else if( not IsNumber(specifier))
- Str1 := "";
- if (zoomBox) begin
- # test to see if zoom box is on screen
- screenList := collect [screen]!;
- for each item in screenList begin
- if not (PtInRect(theHitPoint,item.r)) # see if zoom box on screen
- hitPointOffScreen := true;
- end;
- if (hitPointOffScreen) # can't zoom window
- str := "Couldn't zoom window {Str1}titled '{title}' - zoom box off screen";
- else begin # zoom the window
- zoom [window o:windOrd t:title]!; #To zoom the window
- str := "Zoomed window {Str1}titled '{title}'";
- end;
- end;
- else begin
- str := "No zoom box found in window {Str1}titled '{title}'";
- end;
- LogStr(str);
- return(1);
- end;
- # Error messages
- else begin
- if (specifier > 0)
- Str1 := "!@#$% There was no window of ordinality {specifier} to zoom";
- else if (specifier = 0)
- Str1 := "!@#$% Couldn't find window with grow and zoom box to zoom";
- else if( not IsNumber(specifier))
- Str1 := "!@#$% There was no window titled '{specifier}' to zoom";
- end;
- LogStr(Str1);
- return(0);
- end; # ZoomWindow()
-
-
- ########################################################################
- # ScrollWindow(foo,x,y)
- #=======================================================================
- # Author: KTA/NJV
- # Description: This routine will scroll the specified scrollbar on
- # the active window. If x and y are not passed, then this
- # task will randomly scroll the requested scrollbar.
- # Parameters: foo = 'H' - for horizontal scrollbar
- # = 'V' - for vertical scrollbar
- # <x><y> = the fraction x/y
- # Returns: 0 - Couldn't scroll the scroll bar
- # 1 - Scrolled the scroll bar
- # Examples: ScrollWindow('H',1,2) will scroll the horizontal bar 1/2
- # Assumptions: That the scrollbars are present. This routine collects
- # only the first two scroll bars, which are assumed to be
- # the horizontal and vertical scroll bars.
- # This routine is not 100% reliable.
- #=======================================================================
- # History:
- # KTA/NJV 11/21/89 Created
- # KTA 1/20/89 Added Scrapbook Support
- # KTA 1/20/90 Added LogStr call
- # KTA 5/14/90 Removed scrapbook Support
- # Now checks to see if scrolllbars are enabled
- # NJV 6/25/90 Added random scrolling
- # NJV 7/5/90 Added GetVHScrollBars call.
- # NJV 4/1/91 Updated header for default behavior
- # NJV 6/26/91 Bug fix - enabled scroll bar check now works
- #########################################################################
- task ScrollWindow(foo,x:=-1,y:=-1) begin
- theScrollBars := GetVHScrollBars();
- if (not theScrollBars)
- return(0); # error - couldn't find scroll bars
- vertical := theScrollBars[1];
- verticalDiff := vertical.s;
- horizontal := theScrollBars[2];
- horizontalDiff := horizontal.s;
-
- if (foo = 'V') or (foo = 'v') begin
- if (x=-1) or (y=-1) begin # generate random value
- x := random(0,verticalDiff[2]);
- y := verticalDiff[2];
- end;
- if (vertical.e) begin #Test to see if Scrollbars are enabled
- scroll vertical a:{x,y};
- LogStr("Scrolled the vertical scroll bar Absolute ({x}, {y})");
- end;
- else begin
- LogStr("!@#$% The vertical scroll bar was not enabled to scroll");
- return(0);
- end;
- end;
- else begin
- if (x=-1) or (y=-1) begin # generate random value
- x := random(0,horizontalDiff[2]);
- y := horizontalDiff[2];
- end;
- if (horizontal.e) begin #Test to see if Scrollbars are enabled
- scroll horizontal a:{x,y};
- LogStr("Scrolled the horizontal scroll bar absolute ({x}, {y})");
- end;
- else begin
- LogStr("!@#$% The horizontal scroll bar was not enabled to scroll");
- return(0);
- end;
- end;
- return(1);
- end; # ScrollWindow()
-
- ########################################################################
- # GetVHScrollBars()
- #=======================================================================
- # Author: NJV
- # Description: This routine will return the vertical and horizontal
- # scroll bars.
- # Parameters: None
- # Returns: 0 - Couldn't find scroll bars
- # {vertical,horizontal} - list of vertical and horizontal
- # scroll bars
- # Examples: scrollBars := GetVHScrollBars();
- # Assumptions: Top of vertical scroll bar is at a lower vertical value
- # that the horizontal (i.e. the top of vertical rect is smaller
- # than the top of the horizontal scroll bar's rect).
- #=======================================================================
- # History:
- # NJV 6/25/90 Created
- #########################################################################
- task GetVHScrollBars() begin
- ScrollWindowlist :=collect[scrollbar];
- if not (card(ScrollWindowlist)) begin
- LogStr("!@#$% There were no recognizable scroll bars present");
- return(0);
- end;
- Rec1 := ScrollWindowlist[1];
- Rec2 := ScrollWindowlist[2];
- Rec1R := Rec1.r[1];
- Rec2R := Rec2.r[1];
-
- if (Rec1R < Rec2R) begin #To determine which scroll bar is Vertical/Horizontal
- horizontal := Rec1;
- vertical := Rec2;
- end;
- else begin
- horizontal := Rec2;
- vertical := Rec1;
- end;
- return({vertical,horizontal});
- end;
-
- #########################################################################
- # CloseWindow(howClose, overwrite, specifier,DocName)
- #========================================================================
- # Author: KTA/NJV/DMM
- # Description: This routine will close the specified window. If no
- # parameters are passed to this routine, the default behavior
- # will select the close box of the first window with a close box.
- # Parameters: howClose - 0 - tries all three ways noted below to close the
- # window (if needed)
- # 1 - tries to close window by selecting "Close" menu
- # item
- # 2 - tries to close window by typing "Close" menu
- # item's key equivalent
- # 3 - tries to close window by selecting window's
- # close box
- # overwrite - 0 - will select "No" from a save-changes dialog
- # if one appears when closing window
- # 1 - will select "Yes" to save changes
- # specifier - holds title or ordinality of window to close
- # DocName - string holding new document name - if overWrite
- # parameter is 1, then DocName will be used for
- # naming the file.
- # Returns: 1 - Closed window OK
- # 0 - Couldn't find window to close
- #========================================================================
- # History:
- # KTA/DM 1/20/90 Created
- # NJV 4/07/90 Changed name from CloseW() and added title parameter
- # NJV 4/27/90 Changed to call closeOneWindow and added parameters
- # NJV 5/13/90 Condensed parameters and added CloseOneWindow in-line
- # KTA/NJV 7/17/90 Added DocName parameter, updated checkYesNo calls
- # KTA 8/21/90 Fixed bug in closing by specifier-used to close front window
- # DM 9/24/90 Fixed error meesage for "No window" case. Commented out
- # extra(?) match window
- # DM 9/27/90 Optimized and added FindWindow
- # Changed specifier default to 0 so it will match the
- # first document window.
- # ECH 11/5/90 in howClose 3, closed window using ord and theTitle instead
- # of just theTitle in case two windows have the same name
- # NJV 11/27/90 Addded documentation for DocName
- ###########################################################################
- task CloseWindow(howClose := 3,overwrite := 1,specifier := 0,DocName :="") begin
-
- theWind := FindWindow(specifier);
-
- if theWind begin
- ord := theWind.o;
- theTitle := theWind.t;
- if (ord <> 1)
- SelectWindow(ord);
-
- if (not howClose)
- tryAll := 1;
- else
- tryAll := 0;
-
- if (howClose = 1 or tryAll) begin
- if match [menuItem t: "Close" e: TRUE]! begin
- SelectMenuItem("Close","File");
- checkYesNo(overwrite,DocName);
- return(1);
- end;
- else if not tryAll
- return(0);
- end;
-
- if (howClose = 2 or tryAll) begin
- closeKey := match[menuItem t:"Close"];
- if (closeKey.k) begin
- KeyEq(closeKey.k);
- if (global AppVerify)
- MatchApp(0); #In case or DAs are closed - verifies application
- str := "Typed key-equivalent to close window titled '{theTitle}'";
- LogStr(str);
- checkYesNo(overwrite,DocName);
- return(1);
- end;
- else if not tryAll
- return(0);
- end;
-
- if (howClose = 3 or tryAll) begin
- frontWindow := match[window o:ord t:theTitle c:true]!;
- if (frontWindow) begin
- close [window o:ord t:theTitle c:true]!;
- checkYesNo(overwrite,DocName);
- if (global AppVerify)
- MatchApp(0); #In case DAs are closed - verifies application
- str := "Selected the Close Box on window titled '{theTitle}'";
- LogStr(str);
- return(1);
- end;
- end;
-
- if (tryAll)
- LogStr("!@#$% Couldn't close window by 'Close' menu item, close box, or keyboard equivalent");
- else
- LogStr("!@#$% There is no Close Box Available ");
- return(0);
- end;
- else begin
- if (IsNumber(specifier)) # ordinality
- if (specifier <> 0)
- str := "!@#$% Couldn't find window of ordinality {specifier} to close";
- else
- str := "No windows to close";
- else
- str := "!@#$% Couldn't find window '{specifier}' to close";
- LogStr(str);
- return(0);
- end;
- end; # CloseWindow()
-
-
- #########################################################################
- # MoveRelativeToWindow(x, y, specifier,mouseDown,inset)
- #========================================================================
- # Author: NJV
- # Description: This routine will calculate the window's rectangle
- # and add x and y input parameters to the
- # rectangle's top-left coordinate point. It will then
- # move the mouse to that location. The window is
- # specified by the specifier input parameter. If the
- # specifier parameter is not present, the default
- # behavior will move relative to the frontmost window.
- # Parameters: x - int representing left (x) coord
- # y - int representing top (y) coord
- # specifier - holds title or ordinality of window
- # 0 matches first s:document c:true g:true window
- # mouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # 3 - press mouse key down - move - don't release
- # 4 - move - release
- # inset - inset from window rect for GetXYRandom
- # Returns: Nothing
- # Examples: MoveRelativeToWindow(12,25);
- # Assumptions: Assumes there is a window on the screen
- #========================================================================
- # History:
- # NJV 10/2/89 Created
- # NJV 5/13/90 Changed thePoint parameter to two parameters (x, y)
- # NJV 5/22/90 Added specifier parameter
- # NJV 7/5/90 Added mouseDown and mouseUp parameters for MoveMouse
- # NJV 7/9/90 Added matchTarget parameter for diabling target matching
- # KTA 7/17/90 Added MouseDown = 2 - click after move
- # NJV 7/17/90 Took out matchTarget and mouseUp parameters
- # DM 9/24/90 Added inset param so it can be passed to GetXYRandom.
- # Added 0 option for specifier so it will match the
- # first document window.
- # DM 9/27/90 Optimized and added FindWindow
- #########################################################################
- task MoveRelativeToWindow(x:= 'random', y, specifier:=1,mouseDown:=0,inset:= {30,30,30,30}) begin
- if ( x='random') begin # user wants random mouse move
- xyRandom := GetXYRandom(inset, specifier);
- x := xyRandom[1];
- y := xyRandom[2];
- end;
- theWind := FindWindow(specifier);
- if theWind begin
- lvWindRect := theWind.r;
- lvX := lvWindRect[1]; # X = LEFT (the X co-ord)
- lvY := lvWindRect[2];
- lvFinalLeft := x + lvX; # calculate absolutely X
- lvFinalTop := y + lvY; # calculate absolutely Y
- MoveMouse(lvFinalLeft,lvFinalTop,1,mouseDown); # move to the calculated location
- finalVal := {lvFinalLeft,lvFinalTop};
- return finalVal;
- end;
- else begin
- if (specifier > 0)
- Str1 := "!@#$% Couldn't find a window of ordinality {specifier}";
- else if (specifier = 0)
- Str1 := "!@#$% Couldn't find a window with grow and zoom box";
- else if( not IsNumber(specifier))
- Str1 := "!@#$% Couldn't find a window titled '{specifier}'";
- end;
- end; # MoveRelativeToWindow()
-
-
- #########################################################################
- # MoveMouse(x, y, absolutely, mouseDown)
- #========================================================================
- # Author: DMM
- # Description: This routine will move the mouse x,y relative to
- # it s current location. If x and y are absent or
- # equal to "random", a random move is generated.
- # Parameters: absolutely - 1 if move absolutely, 0 if relative
- # x x distance to move mouse
- # y y distance to move mouse
- # if x and y are absent or := "random" then a
- # random move is generated
- # absolutely - 1 to move to absolute location
- # 0 to move relative to current location
- # mouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # 3 - press mouse key down - move - don't release
- # 4 - move - release
- # Returns: Nothing
- #========================================================================
- # History:
- # DM 4/19/90 Created
- # NJV 4/26/90 Changed to allow for relative or absolutely moving
- # NJV 5/13/90 Re-ordered parameters
- # NJV 7/5/90 Added mouseUp parameter (defaults to original behavior)
- # NJV 7/5/90 Changed 2 LogStr calls to 1.
- # NJV 7/9/90 Added matchTarget parameter (LogStr disables target if mouseDown)
- # KTA 7/17/90 Added MouseDown = 2 - click after move
- # NJV 7/17/90 Took out matchTarget parameter - used mouseDown and mouseUp
- # NJV 7/17/90 Took out mouseUp parameter - changed possible values for mouseDown
- #########################################################################
- task MoveMouse(x := 'random', y := 'random', absolutely := 1, mouseDown := 0)
- begin
- if ( x='random') begin # user wants random mouse move
- xyRandom := getXYRandom();
- x := xyRandom[1];
- y := xyRandom[2];
- end;
-
- if ((mouseDown = 1) or (mouseDown = 3))
- pressMouse;
-
- if (absolutely) begin
- move a: { x, y };
- str := "Moved the mouse to absolute location ∂({x},{y}∂)";
- end;
- else begin
- move r: { x, y };
- str := "Moved the mouse relative ∂({x},{y}∂) to previous position";
- end;
-
- # release mouse if needed
- if ((mouseDown = 1) or (mouseDown = 4))
- releaseMouse;
-
- # add mouse down to log string if needed
- if ((mouseDown = 1) or (mouseDown = 3) or (mouseDown = 4))
- str := "{str} with mouse button held down";
-
- # click if needed
- if (mouseDown = 2 ) begin
- Click;
- str := "{str} and clicked";
- end;
-
- # log it
- LogStr(str);
- end; # MoveMouse()
-
- ########################################################################
- # DrawShapeFrame(specifier := 1,ltrb)
- #=======================================================================
- # Author: DMM
- # Description: Click drags a rectangular frame in the specified window.
- # Parameters: specifier window to draw in; defaults to ordinality 1
- # ltrb {"random"} or {l,t,r,b} of rect to draw
- # inset defines the drawing area relative to the
- # window rectangle
- # Returns: nada
- #=======================================================================
- # History:
- # DM 5/22/90 created
- # DM 9/24/90 Use GetXYRandom to get coords, change
- # ltrb param to a list. Addd inset param
- # so it can be passed to GetXYRandom.
- # DM 9/24/90 Generalized and rolled into control.lib
- #########################################################################
- task DrawShapeFrame(spec := 1,ltrb := {"random"},inset := {0,0,0,0}) begin
-
- if (ltrb[1] = "random") begin
- lrel := "random";
- rRel := "random";
- end;
- else begin
- lRel := ltrb[1];
- tRel := ltrb[2];
- rRel := ltrb[3];
- bRel := ltrb[4];
- end;
- temp := global DisableAllLogging;
- global DisableAllLogging := 1;
- mTemp := mouseSpeed(10);
- lT := MoveRelativeToWindow(lRel,tRel,spec,0,inset);
- rB := MoveRelativeToWindow(rRel,bRel,spec,1,inset);
- mouseSpeed(mTemp);
- global DisableAllLogging := temp;
- left := lT[1]; top := lT[2]; right := rB[1]; bott := rB[2];
- LogStr("Click-Dragged frame from ∂({left},{top}∂) to ∂({right},{bott}∂).");
- end;
-
- #########################################################################
- # NameOK(NameDoc, replaceFlag)
- #========================================================================
- # Author: KTA
- # Description: This routine will type a name (NameDoc) into the text edit
- # field. Then it will press the ReturnKey. If there is a
- # document already named <NameDoc> then this task will check
- # the replaceFlag. If it is defined as anything but true
- # it will select NO to 'Replace Existing?' dialog. It will
- # then type the time (based on a 24 hour clock) after the
- # name and retype the ReturnKey. The Default is to replace
- # an existing document with the same name. It will also call
- # getNewFileName to create a file name if one is not provided.
- # Parameters: NameDoc - string holding the name to name the document
- # replaceFlag - 0 to select 'No' to 'Replace Existing' dialog
- # 1 to select 'Yes' to replace existing file.
- # Returns: string - filename of saved document
- # Examples: NameOk('Untitled1'); to name the file 'Untitled1'
- # Assumptions: That the SF_Put dialog is present
- # A call to SelectMenuItem('Save As', 'File'); should probably
- # be made prior to calling NameOK()
- #========================================================================
- # History:
- # KTA 11/20/89 Created
- # KTA 5/17/90 Added Global LastSavedFile;
- # KTA 6/1/90 Fixed so that the time will be appended in 7.0
- # NJV 6/26/90 Returns filename
- # KTA 7/13/90 Remove Return 0 if no 'Yes' Button
- # NJV 7/27/90 Will keep renaming until original filename
- # KTA 8/2/90 Matches for a dialog
- # KTA 8/22/90 DisableAllLogging after matching for dialog once.
- # NJV 11/27/90 Updated documentation for replaceflag.
- # KTA 12/20/90 Updated for 7.0ß2+ - changes to dialog
- # KTA 2/25/91 Better check for SF Dialog
- #########################################################################
- task NameOK(NameDoc := "", replaceFlag := true) begin
- temp := global DisableAllLogging;
- if (NameDoc = "") begin
- nameDoc := GetNewFileName(); #To get a name #
- end;
- For SFCheck := 1 to 5 begin
- DialogWin := match[window o:1 s:dialog]!;
- if (DialogWin)
- SFCheck := 5;
- else
- LogStr('There is no SF_PUT dialog to name the document with');
- if (SFCheck = 5) and not (DialogWin)
- Return(0);
- end;
- DisableAllLogging :=Temp;
- typeStr("{NameDoc}");
- SpecialKey(returnKey, 'Return Key');
- wait(2);
- Foo := Match[window s:Dialog o:1];
- ButtonName :='';
- while Foo begin
- foo := Match[button t:'Yes']!;
- if foo
- ButtonName := Foo.t;
- else begin
- foo := Match[button t:'Replace']!;
- ButtonName := Foo.t;
- end;
- if (replaceFlag) and (ButtonName) begin #Want to replace
- SelectButton(ButtonName);
- end;
- else begin #Don't want to replace
- if (ButtonName = "Replace") #If match 'Replace' button but don't want to replace select 'Cancel'
- ButtonName := "Cancel";
- else if (ButtonName = "Yes") begin
- ButtonName := "No"; #If match 'Yes' button but don't want to replace select 'No'
- end;
- if ButtonName begin
- SelectButton(ButtonName);
- x := GetNewFileName(nameDoc);
- type k:{ rightArrowKey }; #This is so the time will
- TypeStr("{x}"); #be appended in 6.0/7.0
- SpecialKey(returnKey, 'Return key');
- end;
- namedoc := namedoc + "{x}";
- end;
- if ButtonName
- foo := Match[button t:ButtonName]!;
- end;
-
- LogStr("The documents final name is {namedoc}");
- global LastSavedFile := namedoc;
- return(namedoc);
- end; # NameOK()
-
- #########################################################################
- # GetNewFileName(name)
- #========================================================================
- # Author: SL
- # Description: Gets a new file name by concatenating the app name and
- # the current time.
- # Parameters: name - If this parameter is present, this routine will
- # only pass back the time. If this parameter is not
- # present, then this routine will pass back a string
- # consisting of the application name with the time
- # appended to it.
- # Returns: newFileName - string name for new file name
- #========================================================================
- # History:
- # SL 4/3/90 Created
- # KTA/DM 4/25/90 Reworked the whole thing
- # KTA 8/17/90 Added default parameter so wouldn't recieve error message
- #########################################################################
- task GetNewFileName(name :="") begin
- match [time h:?Tm];
- if not(name = "")
- newFileName := " {Tm}";
- else begin
- match [Application t:?appName];
- newFileName := "@{appName}-{Tm}";
- end; # getNewFileName()
- return(newFileName);
- end; # GetNewFileName()
-
-
- #########################################################################
- # OpenDoc(namedoc,SelectOpen)
- #========================================================================
- # Author: KTA
- # Description: This routine will select 'Open' from the 'File' menu, type
- # the string held in the nameDoc parameter, and
- # then press the returnkey. It will check to see that
- # the frontmost window's title contains namedoc. If not,
- # it assumes that the wrong file opened. It will not select
- # 'Open' if the SelectOpen parameter is 0.
- # Parameters: namedoc - string name of document to open
- # SelectOpen - 0 to disable selecting of the 'Open' menu item.
- # 1 to select 'Open' from the 'File' menu
- # Returns: 1 - Document opened OK
- # 0 - Document not opened OK
- # Assumptions: Works with SF_Get, but don't have NameDoc be to long
- # of a string.
- # Examples: OpenDoc('Untit'); will select a document such as 'Untitled'.
- #========================================================================
- # History:
- # KTA 3/16/90 Created
- # KTA 4/25/90 Changed SelectMenuItem to support by name
- # NJV 6/26/90 Checks to see if window opened is desired window
- # Added return values
- # DMM 6/28/90 Accounted for no window open
- # KTA 9/4/90 Added SelectOpen
- # NJV 11/27/90 Updated documentation for SelectOpen.
- #########################################################################
- task OpenDoc(namedoc, SelectOpen :=1) begin
- global LastSavedFile;
- if (SelectOpen) begin
- selectmenuItem("Open", "File"); #To Select the Open MenuItem
- wait(2);
- end;
- TypeStr(nameDoc); #To Type the documents name (Shouldn't be to long )
- SpecialKey(returnKey, 'Return Key'); #To Select the Default-'OK' to Revert
- wait(3);
-
- x := match[window g:true z:true t:?DocName]!;; #To match the document window
- #To match the top window (Hopefully the Document that was just opened)
- if (not x) begin
- LogStr("!@#$% No open window with grow and zoom boxes");
- return(0); # no open windows - bad
- end;
- LogStr("The front document is named '{DocName}'.");
- if (isSubString(namedoc,DocName)) # looks like the right file
- return(1); # return O'TAY BUCKWHEAT
- else begin
- LogStr("!@#$% It appears that the wrong file was opened, BuckWheat");
- return(0); # nope, wrong file
- end;
- end; # OpenDoc()
-
-
- #########################################################################
- ######### Twitcher 7.31 #############
- #########################################################################
- # This task is intended to select apps from the Process List menu in System 7.0.
- # If the target is using System 7.0 and numIterations is greater than 0
- # it will test Showing, Hiding and twitching to all open apps and the Finder.
- # Unless there is a specific need for this task, this task should be used
- # only by LaunchTwitch. Use LaunchTwitch to handle launching or twitching
- # applications.
-
- #########################################################################
- # Twitcher(appName, numIterations, waitTime)
- #========================================================================
- # Author: DM
- # Description: This routine selects apps from the Process List.
- # If numiterations > 0 it will:
- # • selects the app
- # • selects Hide Others
- # • selects the Finder
- # • selects the same app
- # • selects Hide app
- # • selects Show All
- # • selects the next app
- # for each app in the list.
- # Parameters: appName - app to twitch to after numIterations thru list
- # numIterations - number of times to go thru the whole list.
- # Valid under System 7.0 only!!
- # waitTime - amount of time to wait for twitch to occur. Try
- # inserting a wait time if you are experiencing match
- # errors. 0 works well with a fx host and a SE30 target.
- # Returns: 0 if twitching to appName fails
- # Examples: Twitcher("MacWrite 5.0", 5, 0);
- # Assumptions: None
- #========================================================================
- # History
- # DMM 5/29/90 created
- # DMM 6/26/90 streamlined and updated for a11
- # DMM/KTA 7/31/90 Single twitch and 6.0 compat
- # KTA 12/20/90 Made the Hide check !
- #########################################################################
- task Twitcher(appName := "", numIterations := 0, waitTime := 0) begin
- menuOrd :=1;
- if (Global isSys7) begin
- match[menuItem t:"Hide Others" m:[menu o:?menuOrd] ]!;
- if(numIterations) begin
- itemList := collect[menuItem m:[menu o:menuOrd]];# load list
- numItems := card(itemList);
- menuSelections := {"{theApp}","Hide Others",'Finder',"{theApp}","Hide {theApp}","Show All"};
-
- for i := 1 to numIterations begin
- LogStr("Starting iteration {numIterations}");
- for item := 5 to numItems begin
- theApp := itemList[item].t;
- if theApp <> 'Finder' begin
- for each thing in menuSelections begin
- selectMenuItem(/{thing}≈/);
- wait(waitTime);
- end;
- end;
- end;
- end;
- end;
- end;
-
- y := match[menuItem t:/≈{appName}≈/ m:[menu o:menuOrd] ]!;
- #y := match[menuItem t:/¬"Hide"≈{appName}≈/ m:[menu o:menuOrd] ]!;
- if y begin
- if not(y.t = /Hide≈/!) begin
- select y;
- AppName := y.t;
- LogStr("Selected menuItem {AppName} from the process list");
- wait(2);
- matchApp(1);
- return(1);
- end;
- end;
- else begin
- LogStr("Sorry Charlie, Couldn't select {appName} from the process list");
- return 0;
- end;
- end;
-
- #########################################################################
- # MiniLaunch(appTitle, LaunchApp, SetDir)
- #========================================================================
- # Author: NJV - DMM
- # Description: This routine will launch an application on the target
- # machine(s). The miniLauncher tool should be the running
- # application on the target machine(s). This routine will
- # type the input parameter appTitle to the target machine
- # and then type the return key (which is how an application
- # is launched using miniLauncher.) The application to be
- # launched must reside in a folder beneath the miniLauncher
- # tool in the directory hierarchy. For more information on
- # the miniLauncher tool, see the Read-Me that accompanies
- # the tool. MiniLauncher can be found on the
- # De Anza 6/2nd:SIAC Server:Backup Stuff:VU Heads:MiniLauncher
- # MiniLauncher can also open or print documents. See the
- # LaunchApp parameter description below for more details.
- #
- # Parameters: appTitle - title of the application or document to be launched.
- # The title does not have to be complete. The MiniLauncher
- # tool will launch the first application it finds
- # starting with the string appTitle. If LaunchApp
- # parameter is not 1, then appTitle will hold the
- # document name to be opened or printed.
- # LaunchApp - 1 to launch application
- # 0 to launch application via a document
- # -1 to print a document (launch app and print)
- # SetDir - 1 to set the default directory to that of the
- # application
- # 0 to bypass setting of default directory (will
- # end up being MiniLauncher's directory).
- #
- # Returns: 1 - Launched OK
- # 0 - Couldn't launch application (usually due to lack of
- # enough memory on the target machine).
- #
- # NOTE: Unless there is a specific reason for using this task, the
- # scriptor should use LaunchTwitch instead to make the script
- # independent of the operating system. This task is used
- # by LaunchTwitch.
- #
- # Examples: MiniLaunch('Word');
- #========================================================================
- # History:
- # NJV-DMM 6/21/90 Created
- # NJV 11/27/90 Updated for MiniLauncher v.1.3b - added LaunchApp
- # and SetDir paramters
- #########################################################################
- task MiniLaunch(appTitle, LaunchApp := 1,SetDir := 1) begin
- match [application t:?thisAppTitle]!;
- nextAppTitle := thisAppTitle;
-
- # if LaunchApp is 0 check for newest version of MiniLauncher
- foo := match [button t:'Options']!;
- if (LaunchApp <> 1) begin
- if (not foo) begin
- if (LaunchApp = -1) # user trying to print document
- LogStr("Wrong version of MiniLauncher for printing documents - use v1.3b or newer.");
- else
- LogStr("Wrong version of MiniLauncher for launching documents - use v1.3b or newer.");
- end;
- else
- SelectButton('Options');
- if (LaunchApp = -1) # user wants to print document
- SelectRadioButton('Print Document');
- else
- SelectRadioButton('Open Document');
-
- SelectButton("OK");
- end;
- else if (foo) begin
- SelectButton('Options');
- SelectRadioButton('Launch Application');
- if (SetDir)
- SelectRadioButton("Application∂'s Directory");
- else
- SelectRadioButton("MiniLauncher∂'s Directory");
- SelectButton('OK');
- end;
-
- type k:{"{appTitle}",returnKey};
- while (thisAppTitle = nextAppTitle) begin
- if (match [staticText t:/≈An error has occurred≈/]!) begin
- type k:{returnKey};
- return(0); # application did not launch
- end;
- match [application t:?thisAppTitle]!;
- end;
- MatchApp(0);
- LogStr("Launched {thisAppTitle}");
- return(1);
- end;
-
-
- #########################################################################
- # LaunchTwitch(AppName, Folder, LaunchApp, SetDir)
- #========================================================================
- # Author: KTA
- # Description: This routine determines whether the Operating system is
- # 6.0x or 7.0x and launches the application accordingly.
- # 6.0x - Will check the Apple menu to see if the App is
- # currently running and select it if it is. If it is not running
- # it will select MiniLauncher from the Apple menu and call
- # MiniLaunch(AppName);
- # 7.0x - Will check the ProcessList to see if the App is
- # currently running and select it if it is. if it is not it will
- # Select the Apple from the Apple Menu, or the <Folder> and then type
- # the <AppName> and select the Open menuItem.
- # Parameters: AppName - Application to be launched/Twitched
- # Folder - Folder in the Apple menu that contains <AppName>.
- # LaunchApp - 0 if AppName is name of a document and not an
- # application (for launching app by document
- # via MiniLauncher under 6.0.x)
- # 1 if AppName is name of application to launch
- # SetDir - 0 will not set directory when launching a directory
- # 1 will set directory to application's directory
- # NOTE: This option is not used unless LaunchApp parameter is 1.
- # Returns: 0 - App did not launch
- # 1 - App launched fine
- # 2 - App launched with minimum memory
- # Examples: LaunchTwitch('MacWrite', "#CoreAliases");
- # LaunchTwitch('MacWrite Doc',"#CoreAliases",0);
- # Assumptions: 6.0x - MiniLauncher is a running application
- # 7.0x - That the Application (or Alias) is resident in the
- # Apple Menu or the <Folder> which contains <AppName> is.
- #========================================================================
- # History:
- # KTA 7/31/90 Created
- # KTA 8/2/90 Added- if not( CurrApp.t ~= /≈{AppName}≈/)
- # DM 9/23/90 Added- Timer()
- # NJV 11/27/90 Added LaunchApp and SetDir parameters
- # KTA 12/10/90 Added-match /≈{Folder}≈/ instead of "{Folder}"
- # KTA 12/17/90 Added-match Check for error dialogs
- # NJV/KTA 12/18/90 Added-BailFlag
- # KTA 12/20/90 LaunchApp 1 - for 7.0 Finder launch on
- # 0 - Finder launch off
- # KTA 1/8/90 Removed Timer()
- # KTA 1/9/90 Changed Exits to Return(0)
- # NJV 1/23/91 Returns 1 if app launch OK, 2 if launch in min mem
- # NJV 1/27/91 Disables Integration Module
- # KTA 2/5/91 Changes loop 10 times to loop 2 times
- # KTA 2/24/91 Reset Global AppVerify befroe returning values - bug
- # KTA 2/25/91 /≈{Folder}≈/ to see if correct folder is open
- # KTA 2/25/91 DialogCheck for memory.
- # NJV 3/27/91 Added check for 6.x to see if MiniLauncher is
- # current application.
- # NJV 4/1/91 Updated Header
- #########################################################################
- task LaunchTwitch(AppName, Folder :="",LaunchApp := 1,SetDir := 1) begin
- x := typespeed(50);
- Temp := Global Appverify;
- Global PrevAppTitle := Global AppTitle;
- Appverify := 0;
-
- CurrApp := Match[application];
- returnVal := 1;
-
- if not( CurrApp.t ~= /≈{AppName}≈/) begin
- if (not Twitcher(Appname)) begin
- if (Global isSys7) begin
- if (match[menuItem t:/≈{AppName}≈/ m:[menu t:""]]) begin
- MenuIt :=match[menuItem t:/≈{AppName}≈/ m:[menu t:""]];
- MenuItemName :=MenuIt.t;
- Selectmenuitem("{MenuItemName}", "");
- end;
- else if (LaunchApp = 1) begin
- if (not match[window o:1 t:/≈{Folder}≈/ k:{ [scrollBar e:true] }]!)
- SelectMenuItem("{Folder}", "");
- for theTime := 1 to 3 begin
- if (match[window o:1 t:/≈{Folder}≈/ k:{ [scrollBar e:true]}]!)
- theTime := 4; # break from loop
- else
- wait(1);
- end;
- if not (theTime = 5) begin # couldn't open folder
- LogStr("!@#$% Couldn't open folder titled {Folder} containing requested Alias.");
- returnVal := 0;
- end;
- else begin
- typeStr("{AppName}");
- SelectMenuItem('Open','File');
- end;
- end;
- else begin
- returnVal := 0;
- end;
- end;
- else Begin # running under 6.x Operating System
- if not( CurrApp.t ~= /≈MiniLauncher≈/) begin
- if not (selectMenuItem('MiniLauncher')) begin
- LogStr('MiniLauncher could not be found in the Apple Menu - Aborting');
- returnVal := 0;
- end;
- wait(1);
- end;
- if (returnVal) # if we found MiniLauncher
- MiniLaunch(AppName,LaunchApp,SetDir);
- end;
- end;
- end;
- if (returnVal) begin # we're OK so far - keep checking
- for foo := 1 to 2
- DialogCheck("memory");
- end;
-
- if (returnVal)
- matchApp(0); # To update the Global AppTitle to the new App
- Appverify :=temp;
- typespeed(x);
- return(returnVal);
- end;
-
-
- #########################################################################
- # IsSubString(str1, str2)
- #=======================================================================
- # Author: SL
- # Description: Checks to see if str1 is in str2.
- # Parameters: str1 := Substring to be searched for.
- # str2 := String.
- # Returns: false := str1 is not in str2.
- # true := str1 is in str2.
- #=======================================================================
- # History:
- # SL 6/20/90 Created
- # KTA 9/4/90 Rewrote
- # NJV 4/1/91 Shortened
- #########################################################################
- task IsSubString(str1, str2) begin
- return ( str2 ~= /≈"{str1}"≈/);
- end; # isSubString()
-
- #########################################################################
- # FindPos(char, str, startPos)
- #=======================================================================
- # Author: SL
- # Description: Finds the first occurence of char in str starting
- # from startPos.
- # Parameters: char := A character to be searched for.
- # str := String.
- # startPos:= Starting position to be searched.
- # Returns: 0 := Char is not in str starting from
- # startPos.
- # pos := Char position of its first occurence
- # starting from startPos.
- #=======================================================================
- # History:
- # SL 6/20/90 Created
- #########################################################################
- task FindPos(char, str, startPos:= 1)
- begin
- numStr := card str;
-
- # If start position is greater than the string length, return 0 #
- if (startPos > numStr)
- return(0);
-
- for i:= startPos to numStr do
- begin
- if (char = str[i])
- return(i);
- end; # for
- return(0);
- end; # findPos()
-
-
- #########################################################################
- # Substring(_String,_StartChar,_NumChar)
- #=======================================================================
- # Author: PF
- # Description: returns the first _NumChar characters of the passed _String
- # starting at _StartChar.
- # Parameters: _String - String to use
- # _StartChar - Character to start making substring from
- # _NumChar - Integer number of characters to return
- # Returns: string
- # Assumptions: none
- #=======================================================================
- # History:
- # PF 8/23/90 Created
- # PF 8/27/90 Updated to handle begin anywhere in string
- ##########################################################################
- task Substring(_String,_StartChar,_NumChar) begin
- # first see if number of characters is greater then length of string
- # and return the whole end of the string if it is.
- if (_NumChar > ((card _String ) - _StartChar + 1)) begin
- return (Substring (_String,_StartChar,((card _String) - _StartChar) +1));
-
- end;
- else begin
- # create a string of first _NumChar characters and return it.
- _NewString:=""; #start with an empty string
- for _CharCount :=_StartChar to ((_StartChar + _NumChar) - 1)
- _NewString := _NewString + _String[_CharCount];
- return (_NewString);
- end;
- end; #Substring task
-
- #########################################################################
- # Scrapbook(requestElement,ccpFlag,pasteFlag)
- #========================================================================
- # Author: KTA
- # Description: This routine will select the scrapbook, scroll to the
- # designated requestElement position, select Cut, Copy, Paste,
- # or Clear from the Edit menu, close the scrapbook if under System
- # 6.0.x, and then select Paste if the pasteFlag parameter is 1.
- # Parameters: requestElement - the element in the scrapbook to scroll to
- # ccpFlag - 1 for copy
- # 2 for cut
- # 3 for paste
- # 4 for clear
- # pasteFlag - 1 to paste after closing Scrapbook
- # 0 not to paste after closing Scrapbook
- # Returns: 0 - Couldn't complete operation
- # element - Scrapbook element that operation took place on
- # Examples: Scrapbook(2) will scroll the horizontal bar to the
- # second entry and then copy, close and paste.
- # Assumptions: That the scrollbars are present. That the string
- # 'Scrapbook' appear somewhere in the name
- #========================================================================
- # History:
- # KTA 11/28/89 Created
- # KTA 5/14/90 handles its own scrollbars instead of ScrollWindow()
- # Checks for enabled scrollbars
- # MatchApp(0); for App verification
- # NJV 7/3/90 (x,y) parameters are now just (x)
- # added copyFlag - 1 if copy, 0 if cut
- # NJV 7/5/90 Added pasteFlag - 1 if paste, 0 if don't paste
- # Added error checking to assure requested scrapbook
- # element exists.
- # Added error checking to make sure Cut or Copy menu
- # item selection was successful - if not, routine
- # closes ScrapBook and aborts (returning 0).
- # NJV/KTA 7/13/90 took out wait
- # added while ! match [window t:'Scrapbook' o:1]!);
- # NJV/KTA 7/17/90 changed copyFlag to ccpFlag for paste and clear
- # bug fix from previous re-work
- # NJV 10/9/90 If 7.0, calls LaunchTwitch instead of closing Scrapbook
- # NJV 11/27/90 Updated documentation
- # KTA 1/9/91 Added scrap := 1 to 4
- # KTA 1/24/91 Took out a unneeded comment about checking in the Apple Menu
- # KTA 1/30/91 put in fix for 7.0ß4 where sound button is control [1]
- # KTA 2/18/91 Took out integration - May put this in the Integrate.lib
- # KTA 2/25/91 LaunchTwitch PreviousApp if can launch Scrapbook
- #########################################################################
- task Scrapbook(requestElement,ccpFlag := 1,pasteFlag := 1)
- begin
- println "==========================================================";
- LogStr("Performing Scrapbook DA test.");
-
- if (requestElement = 3) begin
- requestElement := 2;
- logStr("####Patch so we don't try to copy the sound in 7.0ß4");
- end;
- if (ccpFlag > 4)
- ccpFlag := 1; # old default is copy
-
- If(LaunchTwitch('Scrapbook')) begin
- For Scrap := 1 to 4 begin
- scBook := match [window t:'Scrapbook' o:1]!;
- if (scBook)
- scrap := 4;
- else
- launchTwitch("Scrapbook");
- end;
- LogStr("Opened the Scrapbook");
- if(scBook.k[1].t = 'Play Sound') #put in fix for 7.0ß4 where sound button is control [1]
- SkrollBar := scBook.k[2];
- else
- SkrollBar := scBook.k[1];
- status := SkrollBar.s;
- if (status <> { 0, -1 }) begin # if scrollbar is enabled...
- error := 0; # no errors yet
- elementCount := status[2] + 1; # elementCount = number of scrapbook elements
- currentElement := status[1] + 1; # currentElement = current position in Scrapbook
- newCount := elementCount + 1;
-
- if (requestElement>elementCount) begin # if position is greater than total elements in Scrapbook..
- if (ccpFlag = 1)
- LogStr("!@#$% Scrapbook entry {requestElement} does not exist! - Copying entry {currentElement} of {elementCount}");
- else if (ccpFlag = 3)
- LogStr("!@#$% Scrapbook entry {requestElement} does not exist! - Pasting to entry {currentElement} of {newCount}");
- else begin
- LogStr("!@#$% Can∂'t Cut/Clear - Scrapbook entry {requestElement} does not exist! Closing Scrapbook!");
- error := 1; # don't clear or cut if requested item not there
- end;
- end;
- else begin# we've got a valid Scrapbook entry
- scroll SkrollBar a:{requestElement,elementCount};
- match [scrollbar s:?status]!;
- currentElement := status[1] + 1; # currentElement = current position in Scrapbook
- LogStr("Scrolled to item {currentElement} of {elementCount} of the ScrapBook");
- wait(1);
- end;
-
- if (not error) begin
- if (ccpFlag = 1) begin # Copy Item
- if (not SelectMenuItem("Copy", "Edit")) # error - couldn't copy
- error := 1; # prepare to abort
- end;
- else if (ccpFlag = 2) begin
- if (not SelectMenuItem("Cut", "Edit")) # error - couldn't cut
- error := 1; # prepare to abort
- end;
- else if (ccpFlag = 3) begin
- if (not SelectMenuItem("Paste", "Edit")) # error - couldn't cut
- error := 1; # prepare to abort
- else
- LogStr("Pasted to entry {currentElement} of {newCount}");
- end;
- else if (ccpFlag = 4) begin
- if (not SelectMenuItem("Clear", "Edit")) # error - couldn't clear
- error := 1; # prepare to abort
- end;
- end;
- wait(2);
- if (Global isSys7)
- LaunchTwitch(Global PrevAppTitle);
- else
- CloseWindow(); # close ScrapBook
- if (error)
- return(0);
- if (pasteFlag) begin # if we're supposed to paste back into document, do it
- wait(3);
- if (SelectMenuItem("Paste", "Edit")) begin
- println "==========================================================";
- return(1);
- end;
- end;
- return(currentElement); # everything went OK
- end;
- else begin
- LogStr('!@#$% The horizontal scroll bar was not enabled to scroll');
- closeWindow();
- return(0);
- end;
- end;
- else begin
- if (Global isSys7)
- LaunchTwitch(Global PrevAppTitle);
- return(0);
- end;
- end; # Scrapbook()
-
- ########################################################################
- # PageSetup()
- #=======================================================================
- # Author: KTA
- # Description: For PageSetup routines
- # Parameters: Nada
- # Returns: None
- #=======================================================================
- # History:
- # KTA 2/25/91 Created
- ########################################################################
- task PageSetup() begin
- SelectMenuItem("Page Setup", "File"); #To select Page SetUp…
- wait(1);
- SpecialKey(returnKey, 'Return Key'); #To Select the Default-'OK'
- wait(1);
- end;
-
-
-
- ########################################################################
- # GetXYRandom(inset, specifier)
- #=======================================================================
- # Author: SL
- # Description: Returns a random X and Y coordinate in the specified
- # screen or window.
- # Parameters: inset - ltrb inset from scrn or window
- # specifier > 0 ordinality of window to find coords in
- # = O coords in window with s:doc g:true and c:true
- # < 0 coords in specified screen. Screen numbe
- # is negative of specifier.
- # Returns: xyRandom - List of random X and Y. eg. { x, y }
- #=======================================================================
- # History:
- # SL 4/5/90 Created
- # NJV 5/13/90 Added scrn parameter
- # DM 9/23/90 Added option to get random points in front window
- # DM 9/23/90 Changed so the default is random coords in windows
- # rather than screen coords.
- ########################################################################
- task GetXYRandom(inset := {30,30,30,30}, specifier := 0) begin
- (*
- if (not (IsNumber(specifier)))
- match [window t:specifier r:?rect]!;
- else if(specifier > 0)
- match[window o:specifier r:?rect]!;
- else if(specifier = 0)
- match[window s:document r:?rect c:true g:true]!;
-
- if (specifier < 0) begin
- scrList := collect[screen r:?rect]!;
- ScreenCount := 1;
- for each theScreen in scrList begin
- if ScreenCount = -specifier
- scr := theScreen;
- ScreenCount := ScreenCount + 1;
- end;
- end;
- *)
- theDesc := FindWindow(specifier);
-
- if(theDesc) begin
- rect := theDesc.r;
- maxX := rect[3] - rect[1] - inset[3];
- maxY := rect[4] - rect[2] - inset[4];
- #minX := inset[1];
- #minY := inset[2];
- xRandom := random(inset[1], maxX);
- yRandom := random(inset[2], maxY);
- xyRandom := { xRandom, yRandom };
-
- return(xyRandom);
- end;
- else begin
- LogStr("Couldn't match a window of specifier {specifier} in GetXYRandom");
- return 0;
- end;
- end; # getXYRandom()
-
-
- #########################################################################
- # IsNumber(whatAmI)
- #========================================================================
- # Author: NJV
- # Description: This routine determine whether the input parameter is
- # a number or not. This could be done directly in-line,
- # but to avoid Developer's having to modify their code,
- # I updated this routine so that scripts will still work
- # properly unmodified.
- # Parameters: whatAmI - item to check
- # Returns: true - the parameter is a number
- # false - the parameter is not a number
- # Examples: IsNumber("Hello");
- # Assumptions: None
- #========================================================================
- # History:
- # NJV 5/22/90 Created
- # NJV 6/25/91 Now uses TypeOf() VU function
- #########################################################################
- task IsNumber(whatAmI) begin
- return((TypeOf(whatAmI) = 'integer'));
- end; # IsNumber()
-
- #########################################################################
- # PtInRect(thePoint,theRect)
- #========================================================================
- # Author: NJV
- # Description: This routine determines whether or not thePoint
- # is contained within theRect (including borders).
- # Parameters: thePoint - a list of two integers
- # theRect - holds the coordinates of the rectangle.
- # Returns: true - point lies in the rectangle.
- # false - point does NOT lie in the rectangle.
- # Examples: isIt := PtInRect(thePoint,theRect).
- # Assumptions: None
- #========================================================================
- # History:
- # NJV 9/18/90 Created
- #########################################################################
- task PtInRect(thePoint,theRect) begin
- return( ((thePoint[1] >= theRect[1]) and (thePoint[1] <= theRect[3]))
- and ((thePoint[2] >= theRect[2]) and (thePoint[2] <= theRect[4])) );
- end;
-
-
-
- #########################################################################
- # CenterofScreenClick()
- #=======================================================================
- # Author: KTA
- # Description: Clicks in the center of main screen
- # Parameters: none
- # Returns: Nada
- #=======================================================================
- # History:
- # KTA 12/05/90 Added [m:True] to make sure the right screen
- #########################################################################
- task CenterofScreenClick() begin
- Match[screen r:?x m:true];
- w := ((x[3]-x[1])/2);
- h := ((x[4] - x[2])/2);
- move a:{w,h};
- click;
- LogStr('Moved to the center of the screen and clicked');
- end;
-
- #########################################################################
- # Quit(OverWrite, DocName)
- #=======================================================================
- # Author: KTA
- # Description: Will turn off the Application Verification scheme, Select
- # the Quit menu item, check whether or not to save changes,
- # then reset the App verification scheme to its previous state.
- # Parameters: OverWrite 1 - Save changes.
- # 0 - Don't save changes.
- # DocName - The string that will be used to save the document
- # HowQuit 1 - Select "Quit" from File Menu
- # 2 - Type Cmd-Q to quit
- # Returns: Nada
- #=======================================================================
- # History:
- # KA 8/23/90 Created
- # NJV 11/25/90 Added KeepScrapOpen parameter to bypass KAs assumption
- # that ScrapBook is open (fix in scrapbook for 6.0 world).
- # KTA 12/18/90 Took out KeepScrapOpen parameter-auto close Scrap
- # KTA 1/8/91 Moved endTime
- # KTA 1/9/91 Added HowQuit
- # KTA 2/18/91 Added While(CheckYesNo)
- # NJV 4/1/91 Took out Timer
- #########################################################################
- task Quit(OverWrite :=1,DocName:="",HowQuit :=1) begin
- temp := global Appverify;
- AppVerify := 0;
- global startTime;
- if (HowQuit = 1)
- SelectMenuItem('Quit','File'); #Quit MenuItem
- else if (HowQuit = 2)
- keyEq('q'); #Key Equiv 'q'
- while(checkYesNo(overwrite,DocName))
- wait(3);
-
- if match[window o:1 t:"Scrapbook"]!
- closeWindow(,,'Scrapbook');
- wait(2);
- AppVerify := temp;
- MatchApp();
- println;
- println;
- end;
-